<?php
class LogsController extends AppController
{
	var $name = "Logs";

	function index()
	{
		$logItem = array(
			"Log" => array(
				"url" => $_SERVER['HTTP_REFERER'],
				"referrer" => $_GET['r'],
				"client_ip" => $_SERVER['REMOTE_ADDR'],
				"user_agent" => $_SERVER['HTTP_USER_AGENT']
			)
		);
		$this->Log->save($logItem);
	}
	
	function search($clientip = null)
	{
		if (empty($this->data))
		{
			$this->set("logs", $this->Log->find('all', array('order' => 'Log.created desc', 'limit' => 10)));
		}
		else
		{
			$options = array(
				'conditions' => array(
					'Log.client_ip' => $this->data["Log"]["client_ip"]
				),
				'order' => 'Log.created desc',
				'limit' => 10
			);
			$this->set("logs", $this->Log->find('all', $options));
		}
	}
}
?>
